﻿var keyVaule = request('keyVaule');
var bootstrap = function ($, ibpm) {
    "use strict";
    $.BPM_SetForm(top.$.rootUrl + '/Annexes/GetAnnexesFileList?EncObjectId=' + keyVaule, function (data) {
        for (var i = 0, l = data.length; i < l; i++) {
            $('#M_form_file_queue .M-form-file-queue-bg').hide();
            var item = data[i];
            var $item = $('<div class="M-form-file-queue-item" id="M_filequeue_' + item.EncFileID + '" ></div>');
            $item.append('<div class="M-file-image"><img src="' + top.$.rootUrl + '/Playground/Content/images/filetype/' + item.EncType + '.png"></div>');
            $item.append('<span class="M-file-name">' + item.EncName + '(' + ibpm.countFileSize(item.FileSize) + ')</span>');
            $item.append('<div class="M-msg"><i class="fa fa-check-circle"></i></div>');
            $item.append('<div class="M-tool-bar"><i class="fa fa-cloud-download" title="下载" data-id="' + item.EncId + '" data-value="' + item.EncFileID + '" ></i></div>');
            $item.find('.M-tool-bar .fa-cloud-download').on('click', function () {
                var encId = $(this).attr('data-id');
                var fileId = $(this).attr('data-value');
                DownFile(encId, fileId);
            });
            $('#M_form_file_queue_list').append($item);
        }
    });
    // 下载文件
    var DownFile = function (encId, fileId) {
        var param = {};
        param['__RequestVerificationToken'] = $.Token;
        param['EncId'] = encId;
        param['FileId'] = fileId;
        ibpm.download({ url: top.$.rootUrl + '/Annexes/DownAnnexesFile', param, method: 'POST' });
    }
}
